<?php

Yaf_Loader::import(CONTROLLERS_PATH.'Controller.php');
Yaf_Loader::import(EXTEND_PATH.'/qvideo/Videos.php');

class HomeController extends Controller
{
    protected $sdkAppID = 1400043256;
    protected $accountType = 17845;
    public function init()
    {
        $this->authentication = $this->authentication();
        if(!$this->authentication)
        {
            $this->redirect('/');
            exit;
        }
        $this->meeting = new MeetingModel();
        $this->question = new QuestionModel();
        $this->course = new CourseModel();
        $this->getView()->assign("user", $this->authentication['data']);
        $this->group = new GroupModel();
        $group = $this->group->listsAction($this->authentication['data']);
        $this->getView()->assign("group", $group);
    }

    public function indexAction()
    {
        $play = $this->course->liveAction($this->authentication['data']);
        if($play){
            $video['sdkAppID'] = $this->sdkAppID;
            $video['accountType'] = $this->accountType;
            $video['nickname'] = $this->authentication['data']['nickname'];
            $video['udid'] = $this->authentication['data']['id'];
            $video['avatar'] = $this->authentication['data']['avatar'];
            $videos = new Videos();
            $video['url'] = $videos->getPlayUrl($play['channel']);
            $video['tim'] = $this->authentication['tim'];
            $video['channel'] = $play['channel'];
            $this->getView()->assign("video", $video);
        }
        $meetingLive = $this->meeting->liveListsAction($this->authentication['data']['fid'],1,4);
        $meetingBack = $this->meeting->backListsAction($this->authentication['data']['fid'],1,4);
        $live = $this->course->liveListsAction($this->authentication['data'],1,2);
        if($live['count'] || $meetingLive['count']){
            $num = 4;
        }else{
            $num = 8;
        }
        $prior = $this->course->priorListsAction($this->authentication['data'],1,$num);
        $back = $this->course->backListsAction($this->authentication['data'],1,$num);
        $excellent = $this->question->excellentAction($this->authentication['data']['fid'],1);
        $gift = $this->course->giftListsAction();
        $this->getView()->assign("meetingLive", $meetingLive['lists']);
        $this->getView()->assign("meetingBack", $meetingBack['lists']);
        $this->getView()->assign("play", $play);
        $this->getView()->assign("prior", $prior['lists']);
        $this->getView()->assign("live", $live['lists']);
        $this->getView()->assign("back", $back['lists']);
        $this->getView()->assign("excellent", $excellent['top']);
        $this->getView()->assign("gift", $gift);
        $this->getView()->assign("title", '首页');
    }
}
